Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of ADMIN.SH</TITLE>
</HEAD><BODY>
<H1>ADMIN.SH</H1>
Section: User Commands  (1)<BR>Updated: LOCAL<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>

<P>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>

admin.sh - manage starting and stopping modules
<P>
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>

admin.sh 
<I>[options]</I>

<B>-l</B>

<P>
admin.sh
<I>[options] &lt;module&gt;</I>

<B>start|stop|status</B>

<P>
admin.sh
<I>[options] &lt;module&gt;</I>

<B>restart|force-reload</B>

<P>
admin.sh
<I>[options] &lt;module&gt;</I>

<B>try-restart</B>

<P>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>

<B>admin.sh</B>

is like 
<I>LSB (Linux Standard Base) init scripts</I>

but on an application level. 
It can manage a set of modules with launching, stopping or show status of running modules.
<P>
With this script you can manage easily an application using multiples modules.
<P>
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>

<DL COMPACT>
<DT>-M &lt;directory&gt;<DD>
indicates the path of the modules files (see MODULES).
default : admin-modules
<P>
<DT>-E &lt;file&gt;<DD>
indicates the path of the environment file (see MODULES).
default: 
<I>none</I>

<P>
<DT>-l<DD>
: show the list of modules.
<P>
<DT>-A nosys<DD>
action on all modules without
<B>sys </B>

prefix.
Use it instead &lt;module&gt;.
<P>
<DT>-A allsys<DD>
action on all modules.
Use it instead &lt;module&gt;.
<P>
<DT>-v<DD>
show this 
<B>admin.sh </B>

script's version.
<P>
<DT>-?<DD>
show the help message.
<P>
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>COMMANDS</H2>

<DL COMPACT>
<DT>start<DD>
: start a module.
<P>
<DT>stop<DD>
: stop the module.
<P>
<DT>status<DD>
: show the status of the module.
<P>
<DT>restart (or force-reload)<DD>
: stop the module (if running) after restart it.
<I>force-reload is for LSB compatibility.</I>

<P>
<DT>try-restart<DD>
: restart only if the module is running
<P>
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>MODULES</H2>

A module is a file describing how to start, stop or get status of a component.
It's a script file with particular format (see below).
This file contains shell functions and description. 
An environment file can be used too for storing parameters or global functions.
<P>
<A NAME="lbAH">&nbsp;</A>
<H3>Environment file</H3>

It's an optional script launched on current shell (with 
<B>. (dot) </B>

command). This file must be indicated with the 
<B>-E </B>

option.
<P>
<A NAME="lbAI">&nbsp;</A>
<H3>Filename</H3>

This module's file must be in a directory (by default 
<I>admin-modules</I>

) with one of this format :
<I>&lt;number&gt;_&lt;name&gt;</I>

or
<I>&lt;number&gt;_sys_&lt;name&gt;</I>

were 
<DL COMPACT>
<DT>&lt;number&gt;<DD>
is a number. It indicates the order to launch this module when 
<B>-A </B>

option is used. When stopping, the order is reversed.
<P>
<DT>&lt;name&gt;<DD>
is the name you want.
<DT>sys<DD>
is used for indicated a system module.
<P>
</DL>
<A NAME="lbAJ">&nbsp;</A>
<H3>System modules</H3>

A system module represents a component used globally on the system. Like 
<I>ldap server</I>

or
<I>dns server </I>

that is when stopping this component has an impact on the machine and on the other applications.
<P>
<A NAME="lbAK">&nbsp;</A>
<H3>Format of the file</H3>

The file must contain description of the module (comment with NNNA) and 3 shell functions:
<DL COMPACT>
<DT>fn_status<DD>
<DT>fn_start<DD>
<DT>fn_stop.<DD>
<P>
<P>
<P>
Below, a template for the file:
<P>
<BR>&nbsp;#!/bin/sh
<P>
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;description&nbsp;describe&nbsp;here&nbsp;the&nbsp;component&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;you&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version&nbsp;of&nbsp;the&nbsp;script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<P>
<BR>&nbsp;fn_status()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;#get&nbsp;the&nbsp;status&nbsp;of&nbsp;the&nbsp;component&nbsp;(like&nbsp;on&nbsp;System&nbsp;V)
<BR>&nbsp;&nbsp;status=0&nbsp;#0&nbsp;the&nbsp;component&nbsp;is&nbsp;running
<BR>&nbsp;&nbsp;status=1&nbsp;#1&nbsp;the&nbsp;component&nbsp;is&nbsp;dead&nbsp;but&nbsp;PID&nbsp;file&nbsp;exists
<BR>&nbsp;&nbsp;status=2&nbsp;#2&nbsp;the&nbsp;component&nbsp;is&nbsp;dead&nbsp;but&nbsp;lock&nbsp;file&nbsp;exists
<BR>&nbsp;&nbsp;status=3&nbsp;#3&nbsp;the&nbsp;component&nbsp;is&nbsp;stopped
<BR>&nbsp;&nbsp;return&nbsp;$status
<BR>&nbsp;}
<P>
<BR>&nbsp;fn_start()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;#launch&nbsp;the&nbsp;component
<BR>&nbsp;&nbsp;return&nbsp;0&nbsp;#the&nbsp;component&nbsp;is&nbsp;started
<BR>&nbsp;&nbsp;#other&nbsp;exit&nbsp;status&nbsp;=&nbsp;failed&nbsp;
<BR>&nbsp;}
<P>
<BR>&nbsp;fn_stop()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;#stop&nbsp;the&nbsp;component
<BR>&nbsp;&nbsp;return&nbsp;0&nbsp;#the&nbsp;component&nbsp;is&nbsp;stopped
<BR>&nbsp;&nbsp;#other&nbsp;exit&nbsp;status&nbsp;=&nbsp;failed&nbsp;
<BR>&nbsp;}
<P>
<P>
</DL>
<A NAME="lbAL">&nbsp;</A>
<H2>EXAMPLE</H2>

For instance if your application is composed by a website and database, you can create two module : 
<DL COMPACT>
<DT>one for the website<DD>
<DT>another for the database<DD>
<P>
<P>
<P>
</DL>
<A NAME="lbAM">&nbsp;</A>
<H3>Website</H3>

The website is hosted in a virtualhost on a shared Apache server. 
So, the Apache is a system module.
We create the file 
<B>admin-modules/20_sys_apache.</B>

Below the content
<BR>&nbsp;#!/bin/sh
<P>
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;description&nbsp;apache&nbsp;web&nbsp;server&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Example'&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version&nbsp;1.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<P>
<BR>&nbsp;fn_status()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;service&nbsp;apache2&nbsp;status
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}
<P>
<BR>&nbsp;fn_start()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;service&nbsp;apache2&nbsp;start
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}
<P>
<BR>&nbsp;fn_stop()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;service&nbsp;apache2&nbsp;stop
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}
<P>
<A NAME="lbAN">&nbsp;</A>
<H3>Database</H3>

The database instance is launched on standalone but must be launch before Apache.
We create the file
<B>admin-modules/10_database.</B>

Below the content
<BR>&nbsp;#!/bin/sh
<BR>&nbsp;
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;description&nbsp;database&nbsp;of&nbsp;the&nbsp;website&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Example'&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version&nbsp;1.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;#################################################&nbsp;#&nbsp;
<P>
<BR>&nbsp;PG_CTL=/usr/lib/postgresql/9.1/bin/pg_ctl
<BR>&nbsp;
<BR>&nbsp;fn_status()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;su&nbsp;-&nbsp;postgres&nbsp;-c&nbsp;&quot;$PG_CTL&nbsp;status&nbsp;-D&nbsp;/var/nnnadminexample/mydatabase&quot;
<BR>&nbsp;&nbsp;case&nbsp;$?&nbsp;in&nbsp;&nbsp;#transform&nbsp;the&nbsp;pg_ctl&nbsp;exit&nbsp;status&nbsp;on&nbsp;system&nbsp;V
<BR>&nbsp;&nbsp;'0')&nbsp;return&nbsp;0;;
<BR>&nbsp;&nbsp;'1')&nbsp;return&nbsp;3;;
<BR>&nbsp;&nbsp;*)&nbsp;return&nbsp;4;;
<BR>&nbsp;&nbsp;esac
<BR>&nbsp;}
<BR>&nbsp;
<BR>&nbsp;fn_start()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;su&nbsp;-&nbsp;postgres&nbsp;-c&nbsp;&quot;$PG_CTL&nbsp;start&nbsp;-D&nbsp;/var/nnnadminexample/mydatabase&quot;
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}
<P>
<BR>&nbsp;fn_stop()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;su&nbsp;-&nbsp;postgres&nbsp;-c&nbsp;&quot;$PG_CTL&nbsp;stop&nbsp;&nbsp;-D&nbsp;/var/nnnadminexample/mydatabase&quot;
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}
<P>
<A NAME="lbAO">&nbsp;</A>
<H3>Launching database only</H3>

admin.sh database start
<P>
<A NAME="lbAP">&nbsp;</A>
<H3>Showing status for all</H3>

admin.sh -A allsys status
<P>
<A NAME="lbAQ">&nbsp;</A>
<H3>Stopping no system modules</H3>

admin.sh -A nosys stop
<P>
<A NAME="lbAR">&nbsp;</A>
<H3>Restart Apache</H3>

admin.sh apache restart
<P>
<A NAME="lbAS">&nbsp;</A>
<H2>AUTHOR</H2>

3Zen
<P>
<A NAME="lbAT">&nbsp;</A>
<H2>SEE ALSO</H2>

<B><A HREF="/cgi-bin/man/man2html?1+backup.sh">backup.sh</A>(1),</B>

<B><A HREF="/cgi-bin/man/man2html?1+check.sh">check.sh</A>(1),</B>

<B><A HREF="/cgi-bin/man/man2html?1+launch.sh">launch.sh</A>(1)</B>

<P>

<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">OPTIONS</A><DD>
<DT><A HREF="#lbAF">COMMANDS</A><DD>
<DT><A HREF="#lbAG">MODULES</A><DD>
<DL>
<DT><A HREF="#lbAH">Environment file</A><DD>
<DT><A HREF="#lbAI">Filename</A><DD>
<DT><A HREF="#lbAJ">System modules</A><DD>
<DT><A HREF="#lbAK">Format of the file</A><DD>
</DL>
<DT><A HREF="#lbAL">EXAMPLE</A><DD>
<DL>
<DT><A HREF="#lbAM">Website</A><DD>
<DT><A HREF="#lbAN">Database</A><DD>
<DT><A HREF="#lbAO">Launching database only</A><DD>
<DT><A HREF="#lbAP">Showing status for all</A><DD>
<DT><A HREF="#lbAQ">Stopping no system modules</A><DD>
<DT><A HREF="#lbAR">Restart Apache</A><DD>
</DL>
<DT><A HREF="#lbAS">AUTHOR</A><DD>
<DT><A HREF="#lbAT">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 22:11:13 GMT, March 25, 2013
</BODY>
</HTML>
